package com.ego.controller;

import com.ego.dao.OrderDao;
import com.ego.dao.impl.OrderDaoImpl;
import com.ego.pojo.Order;
import com.ego.vo.CartListVo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author 袁梦达 2019012364
 */
@WebServlet("/OrderShowServlet")
public class OrderShowServlet extends HttpServlet {

    private OrderDao orderDao = new OrderDaoImpl();

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String userNumber = String.valueOf(getServletContext().getAttribute("userNumber"));
        if(userNumber == null){
            //未登录
            response.getWriter().print("");
        }else {
            List<Order> orderList = orderDao.showOrder(userNumber);
            StringBuffer stringBuffer = new StringBuffer();
            for (Order order : orderList) {
                stringBuffer.append(order.getOrderId()).append("@")
                        .append(order.getOrderTime()).append("@")
                        .append(order.getQuantity()).append("@")
                        .append(order.getSumPrice()).append("#");
            }
            response.getWriter().print(stringBuffer.toString());
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
